package com.chenfubing.ps.controller;


import com.chenfubing.ps.entity.Community;
import com.chenfubing.ps.entity.result.JsonResult;
import com.chenfubing.ps.service.ICommunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenfubing
 * @since 2020-05-05
 */
@RestController
@RequestMapping("/community")
public class CommunityController {

    @Autowired
    private ICommunityService iCommunityService;

    /**
     * 获取社区列表
     * @return
     */
    @GetMapping("/getCommunityList")
   public JsonResult getCommunityList(){
       return new JsonResult(iCommunityService.getCommunityList());
   }

   @GetMapping("/update")
   public JsonResult update(@RequestParam("name") String name,@RequestParam("address") String address)
   {
       return new JsonResult(iCommunityService.updateById(new Community().setCommunityId(1).setCommunityName(name).setCommunityAddress(address)));
   }

    /**
     * 添加社区
     * @param community
     */
    @PostMapping("/addCommunity")
    public JsonResult addCommunity(@RequestBody Community community){
        iCommunityService.addCommunity(community);
        return new JsonResult();
    }

    @GetMapping("/getOne")
    public JsonResult getOne()
    {
        return new JsonResult(iCommunityService.getBaseMapper().selectById(1)) ;
    }

    @GetMapping("/getCommunitySpaceNum")
    public JsonResult getCommunitySpaceNum(@RequestParam int id){
        return new JsonResult(iCommunityService.getCommunityNumber(id));
    }

    @GetMapping("/updateSpaceNum")
    public JsonResult updateSpaceNum(@RequestParam int number)
    {
        return new JsonResult(iCommunityService.getBaseMapper().updateById(new Community().setCommunityId(1).setCommunitySpaceNumber(number)));
    }

}
